package com.bci.internal.engine.bcibpmengine.controller;


import com.bci.internal.engine.bcibpmengine.service.ActivitiProcessInstanceService;
import com.bci.internal.engine.bcibpmengine.support.RestResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 流程实例控制类
 *
 * @author jzwu
 * @since 2021/4/5 0005
 */
@Api(tags = "通用流程引擎流程实例接口")
@RestController
@RequestMapping("/processInstance")
public class ActivitiProcessInstanceController {
    @Resource
    private ActivitiProcessInstanceService processInstanceService;


    @ApiOperation("启动流程实例")
    @GetMapping(value = "/startProcess")
    public RestResult<?> startProcess(@RequestParam("processDeploymentId") String processDeploymentId,
                                      @RequestParam("instanceName") String instanceName,
                                      @RequestParam("instanceVariable") String instanceVariable) {
        return RestResult.builder().data(processInstanceService.initProcessInstance(processDeploymentId, instanceName, instanceVariable)).build();
    }

    @GetMapping(value = "/getDefinitions")
    public RestResult<?> listProcessDefinitions(@RequestParam("page") int page, @RequestParam("pageSize") int pageSize) {
        return RestResult.builder().data(processInstanceService.listProcessDefinitions(page, pageSize)).build();
    }
}